package com.liang.subject.infra.basic.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liang.subject.infra.basic.entity.SubjectCategory;
import com.liang.subject.infra.basic.entity.SubjectMapping;
import com.liang.subject.infra.basic.mapper.SubjectCategoryMapper;
import com.liang.subject.infra.basic.service.SubjectCategoryService;
import com.liang.subject.infra.basic.service.SubjectMappingService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 29018
 * @description 针对表【subject_category(题目分类)】的数据库操作Service实现
 * @createDate 2024-09-18 22:47:16
 */
@Service
@RequiredArgsConstructor
public class SubjectCategoryServiceImpl extends ServiceImpl<SubjectCategoryMapper, SubjectCategory> implements SubjectCategoryService {

    private final SubjectCategoryMapper subjectCategoryMapper;

    @Override
    public List<SubjectCategory> queryCategory(SubjectCategory subjectCategory) {
        List<SubjectCategory> list = lambdaQuery()
                .eq(SubjectCategory::getCategoryType, subjectCategory.getCategoryType())
                .list();
        return list;
    }

    @Override
    public List<SubjectCategory> queryCategoryByPrimary(SubjectCategory subjectCategory) {
        List<SubjectCategory> list = lambdaQuery()
                .eq(SubjectCategory::getCategoryType, subjectCategory.getCategoryType())
                .eq(SubjectCategory::getParentId, subjectCategory.getParentId())
                .list();
        return list;
    }

    @Override
    public Integer getSubjectCount(Long id) {
        return subjectCategoryMapper.getSubjectCount(id);
//        return (int) subjectMappingService.lambdaQuery().eq(SubjectMapping::getCategoryId, id).list()
//                .stream()
//                .map(SubjectMapping::getSubjectId)
//                .distinct().count();
    }

    @Override
    public List<SubjectCategory> queryAllCategories(Long id) {
        return lambdaQuery()
                .eq(SubjectCategory::getParentId, id)
                .list();
    }
}




